new Vue({
  el: '#app',
  data() {
    return {
      form: {
        Row_Status: '2',
        page: 1,			//页数
        limit: 10,		//每页数据条数
        Article_Name: '',
      },
      formData: {},
      tableData: [],		//表格数据
      total: 1,
      dialogForm: false,
      title: '',
      multipleSelection: []
    }
  },
  mounted() {
    this.getList(this.form)
  },
  methods: {
    onSerach() {				//查询方法
      this.getList(this.form)
    },
    addContract() {
      console.log("跳转")
    },
    getList(data) {     //换页方法
      let _this = this
      $.ajax({
        type: 'POST',
        data,
        url: DomainName + '/getSalesUnitPriceAction?token=' + $.cookie("token"),
        success: function (data) {
          _this.tableData = data.tableData;
          _this.total = Number(data.limit);
          console.log(data)
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      });
    },
    addEnterprise() {
      window.location.href = './Add.html'
    },
    // editMember(Sales_Unit_Price_SerialNumber) {
    //   sessionStorage.setItem("Sales_Unit_Price_SerialNumber", Sales_Unit_Price_SerialNumber)
    //   window.location.href = './Edit.html?Sales_Unit_Price_SerialNumber=' + Sales_Unit_Price_SerialNumber
    // },
    editMember(EnterpriseInfo_SerialNumber) {
      console.log(EnterpriseInfo_SerialNumber)
      sessionStorage.setItem("EnterpriseInfo_SerialNumber", EnterpriseInfo_SerialNumber)
      let _this = this
      let detel = {};
      $.ajax({
        url: DomainName + '/getSalesUnitOriginal',
        type: 'POST',
        data: { Sales_Unit_Price_SerialNumber: EnterpriseInfo_SerialNumber, token: $.cookie("token") },
        success: function (res) {
          if (res.length == 1) {
            console.log(res)
            res[0].Row_Status = '0'
            detel = res[0];
            let data = {
              Data: JSON.stringify({ Modify: { sales_unitprice: [detel] } }),
              token: $.cookie("token")
            };
            $.ajax({
              url: DomainName + '/getEditAction',
              type: 'POST',
              data,
              success: function (res) {
                if (res.Status === 'success') {
                  _this.$message.success("已同意");
                  _this.getList(_this.form);
                } else {
                  _this.$message.error("操作失败，请稍后再试")
                }
              },
              error: function () {
                _this.$message.error("操作失败，请稍后再试")
              },
              complete: function (XMLHttpRequest) {
                _this.loading = false
                if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                  window.parent.document.location.href = "../../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                }
              }
            })
          }
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
    },

    deletMember(Sales_Unit_Price_SerialNumber) {
      this.$confirm('此操作将删除该销售价格单, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        this.delete(Sales_Unit_Price_SerialNumber);
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    delete(Sales_Unit_Price_SerialNumber) {
      const _this = this
      $.ajax({
        url: DomainName + '/SalesUnitpriceId',
        type: 'POST',
        data: { Data: Sales_Unit_Price_SerialNumber },
        success: function (res) {
          if (res.length == 1) {
            res[0].Row_Status = '1'
            let data = { Data: JSON.stringify({ Modify: { sales_unitprice: [res[0]] } }) };
            $.ajax({
              url: DomainName + '/GoodsFileEdit',
              type: 'POST',
              data,
              success: function (re) {
                if (re.Status == "success") {
                  _this.$message.success("作废成功")
                  _this.getList();
                }
              },
              error: function () {
                _this.$message.error("删除失败，请稍后再试")
              },
              complete: function (XMLHttpRequest) {
                _this.loading = false
                if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                  window.parent.document.location.href = "../../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                }
              }
            })
          }
        }
      })
    },

    expandChange(row) {
      let data = row.Sales_Unit_Price_SerialNumber
      let _this = this
      $.ajax({
        type: 'POST',
        data: {
          Sales_Unit_Price_SerialNumber: data
        },
        url: DomainName + '/getSalesUnitPricDetail?token=' + $.cookie("token"),
        success: function (data) {
          row.Children.sales_unitprice_detail = data.Data;
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      });
    },

    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
      this.getList(this.form)
    },
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form)
    },
  },
})